package com.zhoujiulong.assembly_b.testmvvm.viewmodel

import androidx.hilt.lifecycle.ViewModelInject
import androidx.lifecycle.SavedStateHandle
import com.zhoujiulong.assembly_b.testmvvm.repository.TestRepository
import com.zhoujiulong.baselib.base.BaseViewModel
import com.zhoujiulong.baselib.http.listener.RequestListener
import com.zhoujiulong.baselib.http.other.RequestErrorType
import com.zhoujiulong.baselib.http.response.DataResponse
import com.zhoujiulong.baselib.utils.ToastUtil

/**
 * @Description:
 * @Author:  lfc
 * @Email:    iamlifuchang@163.com
 * @CreateTime:     2021/4/13 14:35
 * @UpdateRemark:
 */
class TestViewModel @ViewModelInject constructor(var mRepository: TestRepository) :
    BaseViewModel() {


    fun doTest() {
        showLoading()
        mRepository.requestTest1(object : RequestListener<DataResponse<String>>() {
            override fun requestSuccess(data: DataResponse<String>) {
                ToastUtil.toast("requestSuccess")
            }

            override fun requestError(
                data: DataResponse<String>?,
                type: RequestErrorType,
                msg: String,
                code: Int
            ) {
                ToastUtil.toast("requestError")
            }

            override fun requestComplete(code: Int) {
                super.requestComplete(code)
                hideLoading()
            }

        })
    }

    fun doTest2() {

        showLoading()
        mRepository.requestTest1(object : RequestListener<DataResponse<String>>() {
            override fun requestSuccess(data: DataResponse<String>) {
                hideLoading()
                ToastUtil.toast("requestSuccess")
            }

            override fun requestError(
                data: DataResponse<String>?,
                type: RequestErrorType,
                msg: String,
                code: Int
            ) {
                hideLoading()
                ToastUtil.toast("requestError")
            }

        })
    }
}